﻿//-----------------------------------------------------------------------
// <copyright file="SingleResolutionRuleDescriptor.cs">
//     Copyright (c) Nicole Calinoiu. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Diagnostics.CodeAnalysis;

using Microsoft.FxCop.Sdk;
using Microsoft.VisualStudio.CodeAnalysis.Extensibility;

namespace Bordecal.FxCop.Sdk
{
	/// <summary>
	/// Rule descriptor with a single resolution text pattern.
	/// </summary>
	public class SingleResolutionRuleDescriptor : RuleDescriptor
	{
		#region Fields

		private readonly string _resolution;

		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="SingleResolutionRuleDescriptor"/> class.
		/// </summary>
		/// <param name="category">The rule category.</param>
		/// <param name="name">The rule name.</param>
		/// <param name="description">The rule description.</param>
		/// <param name="checkId">The rule check ID.</param>
		/// <param name="owner">The rule owner.</param>
		/// <param name="email">The rule support e-mail address.</param>
		/// <param name="url">The rule help URL.</param>
		/// <param name="certainty">The default violation certainty.</param>
		/// <param name="fixCategories">The default fix categories.</param>
		/// <param name="messageLevel">The default message level.</param>
		/// <param name="resolution">The resolution text pattern.</param>
		public SingleResolutionRuleDescriptor(
				string category,
				string name,
				string description,
				string checkId,
				string owner,
				string email,
				Uri url,
				int certainty,
				FixCategories fixCategories,
				MessageLevel messageLevel,
				string resolution)
			: base(category, name, description, checkId, owner, email, url, certainty, fixCategories, messageLevel)
		{
			if (resolution == null)
			{
				throw new ArgumentNullException("resolution");
			}

			this._resolution = resolution;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Returns the resolution pattern string for a specified resoution.
		/// </summary>
		/// <param name="name">The resolution pattern name.</param>
		/// <returns>The resolution pattern string.</returns>
		/// <exception cref="InvalidOperationException">The <paramref name="name"/> argument is not null or an empty string.</exception>
		[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "MultipleResolutionRuleDescriptor",
			Justification = "Type name is acceptable here.")]
		[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "TRule",
			Justification = "Type parameter name is acceptable here.")]
		public override string GetResolutionText(string name)
		{
			if (!string.IsNullOrEmpty(name))
			{
				throw new InvalidOperationException("Retrieval of a resolution by name is not supported.  Use a MultipleResolutionRuleDescriptor<TRule> if multiple resolutions are required for a rule.");
			}

			return this._resolution;
		}

		#endregion
	}
}